home *** CD-ROM | disk | FTP | other *** search
- Path: newsserver.trl.OZ.AU!rhea!aduncan
- From: aduncan@rhea.trl.OZ.AU (Allan Duncan)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: 3 bugs in SAS/C v. 6.56
- Date: 28 Feb 1996 04:33:57 GMT
- Organization: Telecom Research Laboratories, Melbourne, Australia.
- Message-ID: <4h0lvl$du2@newsserver.trl.OZ.AU>
- References: <4gs3hk$7mp@gjallar.daimi.aau.dk>
- NNTP-Posting-Host: rhea.trl.oz.au
-
- From article <4gs3hk$7mp@gjallar.daimi.aau.dk>, by liborius@daimi.aau.dk (Per Liboriussen):
- > Thus spake Morten B=?iso-8859-2?Q?=F8geskov Jensen <bogeskov@diku.dk>?=:
- >
- >>#include <stdio.h>
- >
- >>int main(void)
- >>{
- >> unsigned short a = 0xffff, b = 0xffff;
- >
- >> if ((a | b) > (unsigned short)0x7fff) {
- >> printf("ok\n");
- >> } else {
- >> printf("bad\n");
- >> }
- >> return 0;
- >>}
- >
- >>This should work.. But I haven't tested it, since I'm not at home, so I
- >>cannot reach out and get SAS/C.
- >
- > Neither am I, so the same goes for me. However, a working workaround is
- > something like:
-
- Well, I got bad for SAS 6.56, and ok for Gcc on the Sun sparc.
-
- ...
-
- > I don't see what the associativeness of ">" has to do with the above.
- > Anyway, when a compiler evaluates a boolean expression such as ">", it
- > must perform the usual integral promotions. This means that types narrower
- > than int are promoted to int before the comparison. Even in your example
- > above the compiler must take the (integer) constant 0x7fff, convert it to
-
- ^
- unsigned for ANSI
-
- Try this test programme (for a 32 bit int and 2's complement
- arithmetic):
-
- #include <stdio.h>
-
- #define K 0xFFFFFFFF
-
- main()
- {
- printf( "Int %d, long %d, short %d\n", sizeof( int ), sizeof( long int),
- sizeof( short int ) ) ;
- if ( K > 0 ) printf( "ANSI C\n" ) ;
- else printf( " trad C\n" ) ;
- }
-
- > unsigned short, and then immediately convert it back to int. Of course,
- > the ISO C Standard does give permission for an implementation to carry out
- > the comparison by any arcane magic it may wish, as long as a conforming
- > program is not able to tell the difference. (The "as if" rule.)
- >
- > (Note furthermore that even though a and b are both unsigned shorts, the
- > type of the expression (a | b) is int!)
-
- a and b are promoted to int under ANSI, and hence a | b is int. Trad. C
- would have promoted a and b to u-int.
-
- Adding unsigned short c ;
- and setting c = (a | b) before using c in the if changes the SAS
- behaviour. The implication is that SAS are doing a sign extension of a
- and b on the int conversion in the if, but not in the assign...
- now where is that dissassembler...
- Allan Duncan a.duncan@trl.telstra.com.au (+613) 9253 6708, Fax 9253 6664
- Photonics & Reference Standards Section
- Telstra Research Labs, Box 249 Rosebank MDC
- Clayton, Victoria, 3169, Australia (a world renowned Lab in past times)
-